﻿using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;

namespace Bookvar.ObjectModel
{
    /// <summary>
    /// This class keeps information about the position of a topic in a mind map. 
    /// </summary>
    [DataContract]
    [Serializable]
    // TODO: This class should be immutable
    public class TopicPosition : INotifyPropertyChanged
    {
        private Guid id;
        private double x;
        private double y;
        private bool isMoved;

        #region Properties

        /// <summary>
        /// Gets or sets the ID of the TOPIC!
        /// </summary>
        /// <value>The TOPIC ID.</value>
        [SuppressMessage( "Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "ID" )]
        [DataMember]
        public Guid ID
        {
            get { return id; }
            set
            {
                if (id != value)
                {
                    id = value;
                    OnPropertyChanged( new PropertyChangedEventArgs( "ID" ) );
                }
            }
        }

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "X"), DataMember]
        public double X
        {
            get { return x; }
            set
            {
                if (x != value)
                {
                    x = value;
                    OnPropertyChanged(new PropertyChangedEventArgs("X"));
                }
            }
        }

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Y"), DataMember]
        public double Y
        {
            get { return y; }
            set
            {
                if ( y != value )
                {
                    y = value;
                    OnPropertyChanged( new PropertyChangedEventArgs( "Y" ) );
                }
            }
        }

        [DataMember]
        public bool IsMoved
        {
            get { return isMoved; }
            set
            {
                if ( isMoved != value )
                {
                    isMoved = value;
                    OnPropertyChanged( new PropertyChangedEventArgs( "IsMoved" ) );
                }
            }
        }

        #endregion

        public TopicPosition()
        {
        }

        public TopicPosition( Guid id ) : this( id, 0, 0, false )
        {
        }

        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "y")]
        [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "x")]
        public TopicPosition( Guid id, double x, double y, bool isMoved )
        {
            this.id = id;
            this.x = x;
            this.y = y;
            this.isMoved = isMoved;
        }

        public TopicPosition Clone()
        {
            return new TopicPosition( id, x, y, isMoved );
        }

        #region INotifyPropertyChanged Members

        [field : NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged( PropertyChangedEventArgs args )
        {
            if ( PropertyChanged != null )
            {
                PropertyChanged( this, args );
            }
        }

        #endregion
    }
}